var opinionPrice;

/**
 * 设置结果接收对象
 * @param _opinionPrice
 */
function setModel(_opinionPrice) {
    if (_opinionPrice == undefined || !(_opinionPrice instanceof com.jf.crawl.model.OpinionPrice)) {
        throw new java.lang.Exception("opinionPrice 对象为空");
    }
    log.info("opinionPrice {}", _opinionPrice)
    opinionPrice = _opinionPrice;
}

function crawler() {
    var map = new LinkedHashMap();
    for (var i = 1; i < 5; i++) {
        eachGetJF(i, map)
    }
    if (map != null) {
        for (var string in map) {
            var month = string;
            var price = map[string];
            if ("30".equals(month)) {
                opinionPrice.setThreeMonth(commonUtil.string2Decimal(price));
            } else if ("45".equals(month)) {
                opinionPrice.setOneHalfMonth(commonUtil.string2Decimal(price));
            } else if ("60".equals(month)) {
                opinionPrice.setTwoMonth(commonUtil.string2Decimal(price));
            } else if ("90".equals(month)) {
                opinionPrice.setThreeMonth(commonUtil.string2Decimal(price));
            } else if ("180".equals(month)) {
                opinionPrice.setSixMonth(commonUtil.string2Decimal(price));
            } else if ("270".equals(month)) {
                opinionPrice.setNineMonth(commonUtil.string2Decimal(price));
            } else if ("365".equals(month)) {
                opinionPrice.setOneYear(commonUtil.string2Decimal(price));
            } else if ("730".equals(month)) {
                opinionPrice.setTwoYear(commonUtil.string2Decimal(price));
            } else if ("1095".equals(month)) {
                opinionPrice.setThreeYear(commonUtil.string2Decimal(price));
            }
        }
    }
    return true;
}

function eachGetJF(pageNo, map) {
    var url = "https://8.9fpuhui.com/productPlan/productPlanListData.html";
    var params = new LinkedHashMap();
    params.put("queryProfit", "");
    params.put("queryPeriod", "");
    params.put("queryProductCode", "");
    params.put("showType", "K");
    params.put("page", String(pageNo));
    params.put("orderBy", "0");
    params.put("orderByType", "desc");
    params.put("productType", "yx");
    var html = Post(url, null, params);
    var document = Jsoup.parse(html);
    var dds = document.select("dd.po_re");
    for (var i = 0; i < dds.size(); i++) {
        var dd = dds.get(i);
        var status = dd.select(".oplsbut_a").text();
        var price = dd.select(".oplixi.clearfix em").text();
        var num = dd.select(".opinfo-li-r span").text();
        var numType = dd.select(".opinfo-li-r em").text();
        if (status.equals("立即出借")) {
            if (!map.containsKey(num)) {
                map.put(num, price);
            }
        }
    }
}
